import {reqGetdetailInfo,reqAddOrUpdateShopCart} from '@/api'
import {getUUID} from '@/utils/uuid_token'
const state = {
    detailList:{},
    //游客临时身份
    uuid_token:getUUID()
}
const actions = {
    async getdetail({commit},skuId){
      let  result =  await reqGetdetailInfo(skuId)
      if(result.code==200){
        commit('GETDETAIL',result.data)
      }
      console.log(result)
    },
    async addcarts({commit},{skuId,skuNum}){
        let result = await reqAddOrUpdateShopCart(skuId,skuNum)
        //代表服务器加入购物车成功
        if(result.code==200){
            return 'ok'
        }else{
            //代表加入购物车失败
            return Promise.reject(new Error('faile'))
        }
       

    }

}
const mutations = {
    GETDETAIL(state,value){
        state.detailList = value

    }

}
const getters = {
    categoryView(state){
        return state.detailList.categoryView||{}
    },
    skuInfo(state){
        return state.detailList.skuInfo||{}
    },
    spuSaleAttrList(state){
        return state.detailList.spuSaleAttrList || []
    }

}
export default {
    actions,
    mutations,
    state,
    getters

}
